package com.bw.widget.dialog

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.Point
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.WindowManager
import android.widget.ProgressBar
import android.widget.TextView
import com.bawei.llibrary_widget.R


class DownLoadDialog(context:Context) : Dialog(context) {

    private lateinit var title : TextView
    private lateinit var prg : ProgressBar
    lateinit var titleStr : String
    var maxPrg = 0

    fun setPrgNum(prgNum:Int){
        prg.progress = prgNum
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.layout_download_progress)
        window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        setCancelable(false)
        //自定义Dialog宽度
        val m =window!!.windowManager
        val d = m.defaultDisplay
        val p : WindowManager.LayoutParams= window!!.attributes
        val size = Point()
        d.getSize(size)
        p.width =  ((size.x)*0.7).toInt()    //设置为屏幕的0.7倍宽度
        window!!.attributes = p
        title = findViewById(R.id.download_tv)
        prg = findViewById(R.id.download_prg)
        prg.max = maxPrg
        title.text = titleStr
    }

}